﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using Eniux.Windows.ThreeDEngine.Base.CameraControllers;
using System.Windows.Media.Media3D;

namespace Eniux.Windows.ThreeDEngine.AttachObject
{
    public class AttachCamera:AttachBase
    {
        #region 启用开关

        #region IsPanEnabled(平移操作是否可用)
        /// <summary>
        /// 平移操作是否可用属性
        /// </summary>
        public static readonly DependencyProperty IsPanEnabledProperty = DependencyProperty.RegisterAttached("IsPanEnabled", typeof(bool), typeof(AttachCamera), new PropertyMetadata(true));

        /// <summary>
        /// 设置给定依赖对象的IsPanEnabled附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetIsPanEnabled(DependencyObject element, bool value)
        {
            element.SetValue(IsPanEnabledProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的IsPanEnabled附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>IsPanEnabled附加属性的值</returns>
        public static bool GetIsPanEnabled(DependencyObject element)
        {
            return (bool)element.GetValue(IsPanEnabledProperty);
        }
        #endregion

        #region IsRotationEnabled(旋转操作是否可用)
        /// <summary>
        /// 旋转操作是否可用属性
        /// </summary>
        public static readonly DependencyProperty IsRotationEnabledProperty = DependencyProperty.RegisterAttached("IsRotationEnabled", typeof(bool), typeof(AttachCamera), new PropertyMetadata(true));

        /// <summary>
        /// 设置给定依赖对象的IsRotationEnabled附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetIsRotationEnabled(DependencyObject element, bool value)
        {
            element.SetValue(IsRotationEnabledProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的IsRotationEnabled附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>IsRotationEnabled附加属性的值</returns>
        public static bool GetIsRotationEnabled(DependencyObject element)
        {
            return (bool)element.GetValue(IsRotationEnabledProperty);
        }
        #endregion

        #region IsZoomEnabled(旋转操作是否可用)
        /// <summary>
        /// 旋转操作是否可用属性
        /// </summary>
        public static readonly DependencyProperty IsZoomEnabledProperty = DependencyProperty.RegisterAttached("IsZoomEnabled", typeof(bool), typeof(AttachCamera), new PropertyMetadata(true));

        /// <summary>
        /// 设置给定依赖对象的IsZoomEnabled附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetIsZoomEnabled(DependencyObject element, bool value)
        {
            element.SetValue(IsZoomEnabledProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的IsZoomEnabled附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>IsZoomEnabled附加属性的值</returns>
        public static bool GetIsZoomEnabled(DependencyObject element)
        {
            return (bool)element.GetValue(IsZoomEnabledProperty);
        }
        #endregion 

        #endregion

        #region 光标

        #region PanCursor(平移光标)
        /// <summary>
        /// 平移光标属性
        /// </summary>
        public static readonly DependencyProperty PanCursorProperty = DependencyProperty.RegisterAttached("PanCursor", typeof(Cursor), typeof(AttachCamera), new PropertyMetadata(Cursors.Hand));

        /// <summary>
        /// 设置给定依赖对象的PanCursor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetPanCursor(DependencyObject element, Cursor value)
        {
            element.SetValue(PanCursorProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的PanCursor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>PanCursor附加属性的值</returns>
        public static Cursor GetPanCursor(DependencyObject element)
        {
            return (Cursor)element.GetValue(PanCursorProperty);
        }
        #endregion 

        #region RotateCursor(旋转光标)
        /// <summary>
        /// 旋转光标属性
        /// </summary>
        public static readonly DependencyProperty RotateCursorProperty = DependencyProperty.RegisterAttached("RotateCursor", typeof(Cursor), typeof(AttachCamera), new PropertyMetadata(Cursors.SizeAll));

        /// <summary>
        /// 设置给定依赖对象的RotateCursor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetRotateCursor(DependencyObject element, Cursor value)
        {
            element.SetValue(RotateCursorProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的RotateCursor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>RotateCursor附加属性的值</returns>
        public static Cursor GetRotateCursor(DependencyObject element)
        {
            return (Cursor)element.GetValue(RotateCursorProperty);
        }
        #endregion 

        #region ZoomCursor( 缩放光标)
        /// <summary>
        ///  缩放光标属性
        /// </summary>
        public static readonly DependencyProperty ZoomCursorProperty = DependencyProperty.RegisterAttached("ZoomCursor", typeof(Cursor), typeof(AttachCamera), new PropertyMetadata(Cursors.SizeNS));

        /// <summary>
        /// 设置给定依赖对象的ZoomCursor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetZoomCursor(DependencyObject element, Cursor value)
        {
            element.SetValue(ZoomCursorProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的ZoomCursor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>ZoomCursor附加属性的值</returns>
        public static Cursor GetZoomCursor(DependencyObject element)
        {
            return (Cursor)element.GetValue(ZoomCursorProperty);
        }
        #endregion 

        #region ZoomRectangleCursor( 矩形缩放光标)
        /// <summary>
        ///  矩形缩放光标属性
        /// </summary>
        public static readonly DependencyProperty ZoomRectangleCursorProperty = DependencyProperty.RegisterAttached("ZoomRectangleCursor", typeof(Cursor), typeof(AttachCamera), new PropertyMetadata(Cursors.ScrollSE));

        /// <summary>
        /// 设置给定依赖对象的ZoomRectangleCursor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetZoomRectangleCursor(DependencyObject element, Cursor value)
        {
            element.SetValue(ZoomRectangleCursorProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的ZoomRectangleCursor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>ZoomRectangleCursor附加属性的值</returns>
        public static Cursor GetZoomRectangleCursor(DependencyObject element)
        {
            return (Cursor)element.GetValue(ZoomRectangleCursorProperty);
        }
        #endregion 

        #region ChangeFieldOfViewCursor( )
        /// <summary>
        ///  ChangeFieldOfViewCursor属性
        /// </summary>
        public static readonly DependencyProperty ChangeFieldOfViewCursorProperty = DependencyProperty.RegisterAttached("ChangeFieldOfViewCursor", typeof(Cursor), typeof(AttachCamera), new PropertyMetadata(Cursors.ScrollNS));

        /// <summary>
        /// 设置给定依赖对象的ChangeFieldOfViewCursor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetChangeFieldOfViewCursor(DependencyObject element, Cursor value)
        {
            element.SetValue(ChangeFieldOfViewCursorProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的ChangeFieldOfViewCursor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>ChangeFieldOfViewCursor附加属性的值</returns>
        public static Cursor GetChangeFieldOfViewCursor(DependencyObject element)
        {
            return (Cursor)element.GetValue(ChangeFieldOfViewCursorProperty);
        }
        #endregion 

        #endregion

        #region MinimumFieldOfView
        /// <summary>
        /// MinimumFieldOfView属性
        /// </summary>
        public static readonly DependencyProperty MinimumFieldOfViewProperty = DependencyProperty.RegisterAttached("MinimumFieldOfView", typeof(double), typeof(AttachCamera), new PropertyMetadata(5.0));

        /// <summary>
        /// 设置给定依赖对象的MinimumFieldOfView附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetMinimumFieldOfView(DependencyObject element, double value)
        {
            element.SetValue(MinimumFieldOfViewProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的MinimumFieldOfView附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>MinimumFieldOfView附加属性的值</returns>
        public static double GetMinimumFieldOfView(DependencyObject element)
        {
            return (double)element.GetValue(MinimumFieldOfViewProperty);
        }
        #endregion 

        #region MaximumFieldOfView
        /// <summary>
        /// MaximumFieldOfView属性
        /// </summary>
        public static readonly DependencyProperty MaximumFieldOfViewProperty = DependencyProperty.RegisterAttached("MaximumFieldOfView", typeof(double), typeof(AttachCamera), new PropertyMetadata(160.0));

        /// <summary>
        /// 设置给定依赖对象的MaximumFieldOfView附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetMaximumFieldOfView(DependencyObject element, double value)
        {
            element.SetValue(MaximumFieldOfViewProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的MaximumFieldOfView附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>MaximumFieldOfView附加属性的值</returns>
        public static double GetMaximumFieldOfView(DependencyObject element)
        {
            return (double)element.GetValue(MaximumFieldOfViewProperty);
        }
        #endregion 

        #region RotationSensitivity（旋转灵敏度）
        /// <summary>
        /// 旋转灵敏度属性
        /// </summary>
        public static readonly DependencyProperty RotationSensitivityProperty = DependencyProperty.RegisterAttached("RotationSensitivity", typeof(double), typeof(AttachCamera), new PropertyMetadata(1.0));

        /// <summary>
        /// 设置给定依赖对象的RotationSensitivity附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetRotationSensitivity(DependencyObject element, double value)
        {
            element.SetValue(RotationSensitivityProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的RotationSensitivity附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>RotationSensitivity附加属性的值</returns>
        public static double GetRotationSensitivity(DependencyObject element)
        {
            return (double)element.GetValue(RotationSensitivityProperty);
        }
        #endregion 

        #region ZoomSensitivity（缩放灵敏度）
        /// <summary>
        /// 缩放灵敏度属性
        /// </summary>
        public static readonly DependencyProperty ZoomSensitivityProperty = DependencyProperty.RegisterAttached("ZoomSensitivity", typeof(double), typeof(AttachCamera), new PropertyMetadata(1.0));

        /// <summary>
        /// 设置给定依赖对象的ZoomSensitivity附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetZoomSensitivity(DependencyObject element, double value)
        {
            element.SetValue(ZoomSensitivityProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的ZoomSensitivity附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>ZoomSensitivity附加属性的值</returns>
        public static double GetZoomSensitivity(DependencyObject element)
        {
            return (double)element.GetValue(ZoomSensitivityProperty);
        }
        #endregion 

        #region RotateAroundMouseDownPoint
        /// <summary>
        /// RotateAroundMouseDownPoint属性
        /// </summary>
        public static readonly DependencyProperty RotateAroundMouseDownPointProperty = DependencyProperty.RegisterAttached("RotateAroundMouseDownPoint", typeof(bool), typeof(AttachCamera), new PropertyMetadata(false));

        /// <summary>
        /// 设置给定依赖对象的RotateAroundMouseDownPoint附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetRotateAroundMouseDownPoint(DependencyObject element, bool value)
        {
            element.SetValue(RotateAroundMouseDownPointProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的RotateAroundMouseDownPoint附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>RotateAroundMouseDownPoint附加属性的值</returns>
        public static bool GetRotateAroundMouseDownPoint(DependencyObject element)
        {
            return (bool)element.GetValue(RotateAroundMouseDownPointProperty);
        }
        #endregion 

        #region ZoomAroundMouseDownPoint
        /// <summary>
        /// ZoomAroundMouseDownPoint属性
        /// </summary>
        public static readonly DependencyProperty ZoomAroundMouseDownPointProperty = DependencyProperty.RegisterAttached("ZoomAroundMouseDownPoint", typeof(bool), typeof(AttachCamera), new PropertyMetadata(false));

        /// <summary>
        /// 设置给定依赖对象的ZoomAroundMouseDownPoint附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetZoomAroundMouseDownPoint(DependencyObject element, bool value)
        {
            element.SetValue(ZoomAroundMouseDownPointProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的ZoomAroundMouseDownPoint附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>ZoomAroundMouseDownPoint附加属性的值</returns>
        public static bool GetZoomAroundMouseDownPoint(DependencyObject element)
        {
            return (bool)element.GetValue(ZoomAroundMouseDownPointProperty);
        }
        #endregion 

        #region InertiaFactor（惯性因子）
        /// <summary>
        /// 惯性因子属性
        /// </summary>
        public static readonly DependencyProperty InertiaFactorProperty = DependencyProperty.RegisterAttached("InertiaFactor", typeof(double), typeof(AttachCamera), new PropertyMetadata(0.9));

        /// <summary>
        /// 设置给定依赖对象的InertiaFactor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetInertiaFactor(DependencyObject element, double value)
        {
            element.SetValue(InertiaFactorProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的InertiaFactor附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>InertiaFactor附加属性的值</returns>
        public static double GetInertiaFactor(DependencyObject element)
        {
            return (double)element.GetValue(InertiaFactorProperty);
        }
        #endregion 

        #region ShowCameraTarget（是否显示相机目标）
        /// <summary>
        /// 是否显示相机目标属性
        /// </summary>
        public static readonly DependencyProperty ShowCameraTargetProperty = DependencyProperty.RegisterAttached("ShowCameraTarget", typeof(bool), typeof(AttachCamera), new PropertyMetadata(true));

        /// <summary>
        /// 设置给定依赖对象的ShowCameraTarget附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetShowCameraTarget(DependencyObject element, bool value)
        {
            element.SetValue(ShowCameraTargetProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的ShowCameraTarget附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>ShowCameraTarget附加属性的值</returns>
        public static bool GetShowCameraTarget(DependencyObject element)
        {
            return (bool)element.GetValue(ShowCameraTargetProperty);
        }
        #endregion 

        #region CameraMode（相机模式）
        /// <summary>
        /// 相机模式属性
        /// </summary>
        public static readonly DependencyProperty CameraModeProperty = DependencyProperty.RegisterAttached("CameraMode", typeof(CameraMode), typeof(AttachCamera), new PropertyMetadata(CameraMode.Inspect));

        /// <summary>
        /// 设置给定依赖对象的CameraMode附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetCameraMode(DependencyObject element, CameraMode value)
        {
            element.SetValue(CameraModeProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的CameraMode附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>CameraMode附加属性的值</returns>
        public static CameraMode GetCameraMode(DependencyObject element)
        {
            return (CameraMode)element.GetValue(CameraModeProperty);
        }
        #endregion 

        #region CameraRotationMode（相机旋转模式）
        /// <summary>
        /// 相机旋转模式属性
        /// </summary>
        public static readonly DependencyProperty CameraRotationModeProperty = DependencyProperty.RegisterAttached("CameraRotationMode", typeof(CameraRotationMode), typeof(AttachCamera), new PropertyMetadata(CameraRotationMode.Turntable));

        /// <summary>
        /// 设置给定依赖对象的CameraRotationMode附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetCameraRotationMode(DependencyObject element, CameraRotationMode value)
        {
            element.SetValue(CameraRotationModeProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的CameraRotationMode附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>CameraRotationMode附加属性的值</returns>
        public static CameraRotationMode GetCameraRotationMode(DependencyObject element)
        {
            return (CameraRotationMode)element.GetValue(CameraRotationModeProperty);
        }
        #endregion 

        #region InfiniteSpin
        /// <summary>
        /// InfiniteSpin属性
        /// </summary>
        public static readonly DependencyProperty InfiniteSpinProperty = DependencyProperty.RegisterAttached("InfiniteSpin", typeof(bool), typeof(AttachCamera), new PropertyMetadata(false));

        /// <summary>
        /// 设置给定依赖对象的InfiniteSpin附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetInfiniteSpin(DependencyObject element, bool value)
        {
            element.SetValue(InfiniteSpinProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的InfiniteSpin附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>InfiniteSpin附加属性的值</returns>
        public static bool GetInfiniteSpin(DependencyObject element)
        {
            return (bool)element.GetValue(InfiniteSpinProperty);
        }
        #endregion 

        #region ModelUpDirection（模型向上方向）
        /// <summary>
        /// 模型向上方向属性
        /// </summary>
        public static readonly DependencyProperty ModelUpDirectionProperty = DependencyProperty.RegisterAttached("ModelUpDirection", typeof(Vector3D), typeof(AttachCamera), new PropertyMetadata(new Vector3D(0, 0, 1)));

        /// <summary>
        /// 设置给定依赖对象的ModelUpDirection附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <param name="value">值</param>
        public static void SetModelUpDirection(DependencyObject element, Vector3D value)
        {
            element.SetValue(ModelUpDirectionProperty, value);
        }

        /// <summary>
        /// 获取给定依赖对象的ModelUpDirection附加属性的值
        /// </summary>
        /// <param name="element">依赖对象</param>
        /// <returns>ModelUpDirection附加属性的值</returns>
        public static Vector3D GetModelUpDirection(DependencyObject element)
        {
            return (Vector3D)element.GetValue(ModelUpDirectionProperty);
        }
        #endregion 

        public static void AddOwner(Type type)
        {
            AttachCamera.IsPanEnabledProperty.AddOwner(type);
            AttachCamera.IsRotationEnabledProperty.AddOwner(type);
            AttachCamera.IsZoomEnabledProperty.AddOwner(type);

            AttachCamera.PanCursorProperty.AddOwner(type);
            AttachCamera.RotateCursorProperty.AddOwner(type);
            AttachCamera.ZoomCursorProperty.AddOwner(type);
            AttachCamera.ZoomRectangleCursorProperty.AddOwner(type);
            AttachCamera.ChangeFieldOfViewCursorProperty.AddOwner(type);

            AttachCamera.MinimumFieldOfViewProperty.AddOwner(type);
            AttachCamera.MaximumFieldOfViewProperty.AddOwner(type);
            AttachCamera.RotationSensitivityProperty.AddOwner(type);
            AttachCamera.ZoomSensitivityProperty.AddOwner(type);
            AttachCamera.RotateAroundMouseDownPointProperty.AddOwner(type);
            AttachCamera.ZoomAroundMouseDownPointProperty.AddOwner(type);
            AttachCamera.InertiaFactorProperty.AddOwner(type);
            AttachCamera.ShowCameraTargetProperty.AddOwner(type);
            AttachCamera.CameraModeProperty.AddOwner(type);
            AttachCamera.CameraRotationModeProperty.AddOwner(type);
            AttachCamera.InfiniteSpinProperty.AddOwner(type);
            AttachCamera.ModelUpDirectionProperty.AddOwner(type);
        }
    }
}
